package com.book.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import com.book.entity.BookChapter;
import com.book.entity.BookInfo;
import com.book.entity.BookMember;
import com.book.entity.BookType;
import com.book.entity.Teacher;
import com.github.drinkjava2.jsqlbox.ActiveRecord;

public class BeanUtils {
	 
	 public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public static void setProperty(ActiveRecord<?> eo,String name,String value) {
		if(eo instanceof Teacher){
			setProperty((Teacher)eo, name, value);
		}else if(eo instanceof BookType) {
			setProperty((BookType)eo, name, value);
		}else if(eo instanceof BookInfo) {
			setProperty((BookInfo)eo, name, value);
		}else if(eo instanceof BookChapter) {
			setProperty((BookChapter)eo, name, value);
		}else if(eo instanceof BookMember) {
			setProperty((BookMember)eo, name, value);
		}
	}
	
	public static void setProperty(BookMember eo,String name,String value) {
		 switch (name) {
		 case "memberId":
			 if(value == null || value.trim().equals("")) {
				 eo.setMemberId(null);
			 }else {
				 eo.setMemberId(Integer.parseInt(value));
			 }
			 break;
		 case "loginname":
			 eo.setLoginname(value);
			 break;
		 case "password":
			 eo.setPassword(value);
			 break;
		 case "email":
			 eo.setEmail(value);
			 break;
		 case "phone":
			 eo.setPhone(value);
			 break;
		 case "duedate":
				try {
					eo.setDuedate(sdf.parse(value));
				} catch (ParseException e) {
					e.printStackTrace();
				}
				 break;
		 case "createTime":
			try {
				eo.setCreateTime(sdf.parse(value));
			} catch (ParseException e) {
				e.printStackTrace();
			}
			 break;
		
		 default:
			 break;
		}		
	}
	
	
	
	
	public static void setProperty(BookChapter eo,String name,String value) {
		 switch (name) {
		 case "chapterId":
			 if(value == null || value.trim().equals("")) {
				 eo.setChapterId(null);
			 }else {
				 eo.setChapterId(Integer.parseInt(value));
			 }
			 break;
		 case "bookId":
			 if(value == null || value.trim().equals("")) {
				 eo.setBookId(null);
			 }else {
				 eo.setBookId(Integer.parseInt(value));
			 }
			 break;
		 case "chapterName":
			 eo.setChapterName(value);
			 break;
		 case "chapterText":
			 eo.setChapterText(value);
			 break;
		 case "createTime":
			try {
				eo.setCreateTime(sdf.parse(value));
			} catch (ParseException e) {
				e.printStackTrace();
			}
			 break;
		
		 default:
			 break;
		}		
	}
	
	
	
	
	
	public static void setProperty(BookInfo eo,String name,String value) {
		 switch (name) {
		 case "typeId":
			 if(value == null || value.trim().equals("")) {
				 eo.setTypeId(null);
			 }else {
				 eo.setTypeId(Integer.parseInt(value));
			 }
			 break;
		 case "bookId":
			 if(value == null || value.trim().equals("")) {
				 eo.setBookId(null);
			 }else {
				 eo.setBookId(Integer.parseInt(value));
			 }
			 break;
		 case "bookName":
			 eo.setBookName(value);
			 break;
		 case "bookTesc":
			 eo.setBookTesc(value);
			 break; 
		 case "bookAuthor":
			 eo.setBookAuthor(value);
			 break;
		 case "createTime":
			try {
				eo.setCreateTime(sdf.parse(value));
			} catch (ParseException e) {
				e.printStackTrace();
			}
			 break;
		 case "imgUrl":
			 eo.setImgUrl(value);
			 break;
		 case "srcurl1":
			 eo.setSrcUrl1(value);
			 break;
		 case "dianZan":
			 eo.setDianZan(Integer.parseInt(value));
			 break;
		 default:
			 break;
		}		
	}
	
	
	
	public static void setProperty(BookType eo,String name,String value) {
		 switch (name) {
		 case "typeId":
			 if(value == null || value.trim().equals("")) {
				 eo.setTypeId(null);
			 }else {
				 eo.setTypeId(Integer.parseInt(value));
			 }
			 break;
		 case "typeName":
			 eo.setTypeName(value);
			 break;
		 case "createTime":
			try {
				eo.setCreateTime(sdf.parse(value));
			} catch (ParseException e) {
				e.printStackTrace();
			}
			 break;
		
		 default:
			 break;
		}		
	}
	
		
	public static void setProperty(Teacher eo,String name,String value) {
		 switch (name) {
		 case "id":
			 if(value == null || value.trim().equals("")) {
				 eo.setId(null);
			 }else {
				 eo.setId(Integer.parseInt(value));
			 }
			 break;
		 case "username":
			 eo.setUsername(value);
			 break;
		 case "password":
			 eo.setPassword(value);
			 break;
		 case "type":
			 if(value == null || value.trim().equals("")) {
				//
			 }else {
				eo.setType(value);
			 }
			 break;
		 case "sex":
			 eo.setSex(Integer.parseInt(value));
			 break;
		 case "amail":
			 eo.setAmail(value);
			 break;
		 case "phone":
			 eo.setPhone(value);
			 break;
		 case "nicheng":
			 eo.setNicheng(value);
			 break;
		 case "imgUrl":
			 eo.setImgUrl(value);
			 break;
		 default:
			 break;
		}		
	}
	
}
